#include <iostream>
using namespace std;

const int N = 10;

int n;
char g[N][N];
bool r[N], c[N], ld[2 * N], rd[2 * N];

void dfs(int i, int j, int s)
{
    if (j == n)
        ++i, j = 0;
    if (i == n)
    {
        if (s == n)
        {
            for (int k = 0; k < n; ++k)
                puts(g[k]);
            puts("");
            return;
        }
        return;
    }
    g[i][j] = '.';
    dfs(i, j + 1, s);                                       //选择不在这里放皇后
    if (!r[i] && !c[j] && !ld[i + j] && !rd[i + n - 1 - j]) //选择尝试在这里放皇后
    {
        g[i][j] = 'Q';
        r[i] = true;
        c[j] = true;
        ld[i + j] = true;
        rd[i + n - 1 - j] = true;
        dfs(i, j + 1, s + 1);
        g[i][j] = '.';
        r[i] = false;
        c[j] = false;
        ld[i + j] = false;
        rd[i + n - 1 - j] = false;
    }
    //return;
}

int main()
{
    cin >> n;
    dfs(0, 0, 0);
    return 0;
}